<?php

require_once 'class.character.php';

class bank extends character {
	
	public $properties = array();
	
	public function setBank_Character($char_id)
	{
		$this -> setData("SELECT b.account_id AS account_id, b.character_id AS character_id, b.account_balance AS account_balance, c.character_money FROM bank b LEFT JOIN characters c ON c.character_id = b.character_id WHERE c.character_id = $char_id");
		if($this -> numrows > 0)
		{
			$this -> properties = $this -> getData();
		} else {
			$this -> properties = array(FALSE);
		}
	}
	
	public function getBank_Character()
	{
		return $this -> properties;
	}
	
	public function activateBank_Character($char_id)
	{
		$rd = $this -> characterRegistry($char_id);
		if($rd['character_money'] >= $money)
		{
			$aid = $rd['account_id'];
			$this -> getAction("INSERT INTO bank VALUES ({$aid},{$char_id}, 25)");
				return TRUE;
		} else {
			return FALSE;
		}
	}
	
	public function addMoneyToBank($char_id = array(), $money)
	{
		if($money > 0 AND count($char_id) == 2)
		{
			$rd = $this -> characterRegistry($char_id[0]);
			if($rd['character_money'] >= $money)
			{
				$this -> getAction("UPDATE bank SET account_balance = (account_balance + {$money}) WHERE character_id = {$char_id[1]}");
					return TRUE;
			} else {
				return FALSE;
			}
		} else {
			return FALSE;
		}
	}
	
	public function deleteMoneyToBank($char_id, $money)
	{
		if($money > 0 AND count($char_id) == 2)
		{
			$rd = $this -> characterRegistry($char_id[0]);
			if($rd['character_money'] <= $money)
			{
				$this -> getAction("UPDATE bank SET account_balance = 0 WHERE character_id = {$char_id[0]}");
					return TRUE;
			} else {
				$this -> getAction("UPDATE bank SET account_balance = (account_balance - {$money}) WHERE character_id = {$char_id[1]}");
					return TRUE;
			}
		} else {
			return FALSE;
		}
	}
	
	public function deleteBank($char_id)
	{
		if($char_id != 0)
		{
			$this -> getAction("DELETE FROM bank WHERE character_id = {$char_id}");
				return TRUE;
		} else {
			return FALSE;
		}
	}
	
}


?>